//
// Created by Scave on 2023/11/11.
//

#ifndef RIDER3D_SCENE_H
#define RIDER3D_SCENE_H


#include "Define.h"
#include "entityx/entityx.h"
#include "entityx/help/Timer.h"
#include "component/Supposition.h"
#include "component/BasicComponents.h"
#include "event/ExternalListener.h"

NS_RIDER_BEGIN

    enum struct PrimitiveType {
        Rectangle = 0,
        Triangle = 1,
        Box = 10,
        Sphere = 11,
        SkyBox = 12,
        Capsule = 13,
        Cylinder = 14,
        Torus = 15,
        TriangularPyramid = 16
    };

    class Scene {
        friend class SceneManager;
    private:
        Scene();
        Scene(const String& name);

    public:

        ~Scene();

        void SetCamera(Camera camera);

        void SetDebugInfo(DebugInfo debug_info);

        void SetSceneConfig(SceneConfig config);

        void AddEntity(Entity& entity);

        void AddEntityAt(ENTITY_SIZE_TYPE index, Entity& entity);

        void RemoveEntity(Entity& entity);

        void RemoveEntityAt(ENTITY_SIZE_TYPE index);

        Entity GetEntityAt(ENTITY_SIZE_TYPE index);

        Entity FindEntity(const Name& name);

        Entity operator[](ENTITY_SIZE_TYPE index);

        Entity operator[](const Name& name);

        ENTITY_SIZE_TYPE Size();

        String& GetName();

        Entity CreatePrimitiveEntity(PrimitiveType type, const Name& name);

        EntityManager& GetEntityManager();

        void Update();

        void OnLoad();

        void OnUnLoad();

        void OnPause();

        void OnResume();

        void SetEventListener(SMART_PTR<SceneEventListener>& listener);
    private:
        String name_;
        EntityManager entities_;
        EventManager events_;
        SystemManager systems_;
        std::vector<Entity> entity_list_;
        Entity root_entity_;
        help::Timer timer_;

        void ResetEntityComponentSystems();
    };

NS_RIDER_END

#endif //RIDER3D_SCENE_H
